package com.cqemme.hardwareservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.cqemme.comm.po.NoteMessage;
import com.cqemme.hardwareservice.util.EmptyChecker;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("/test")
@CrossOrigin
@Api(value = "自己的测试控制器")
public class TestController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @RequestMapping("/test")
    @ResponseBody
    public Object login() {
        String a = "0E121.411783N31.178125T20080121165030000030015";
        //gps点内容
        String d4 = a;
        String[] gpsArr = d4.split("!");
        List<Map<String, String>> gpsList = new ArrayList<>();
        for (int i = 0; i < gpsArr.length; i++) {
            try {
                String gpsStr = gpsArr[i];
                Map<String, String> gps = new HashMap<>();
                //gps状态 0：表示定位成功,GPS位置  1：表示WIFI定位失败  2：表示WIFI定位成功-GPS未打开或GPS位置暂不用等其它情况
                gps.put("Gps-Status", gpsStr.substring(0, 1));
                //经度标识  E：表示东经    W：表示西经
                gps.put("Longitude-Type", gpsStr.substring(1, 2));
                int nI = 0;
                if ((nI = gpsStr.indexOf("N")) > 3) {
                } else if ((nI = gpsStr.indexOf("S")) > 3) {
                } else if ((nI = gpsStr.indexOf("n")) > 3) {
                } else if ((nI = gpsStr.indexOf("s")) > 3) {
                }
                //经度
                gps.put("Longitude", gpsStr.substring(2, nI));
                //维度标识
                gps.put("Latitude-Type", gpsStr.substring(nI, nI + 1));
                int tI = 0;
                if ((tI = gpsStr.indexOf("T")) > 3) {
                } else if ((nI = gpsStr.indexOf("t")) > 3) {
                }
                //维度
                gps.put("Latitude",gpsStr.substring(nI+1, tI));
                //时间
                gps.put("Time",gpsStr.substring(tI+1));
                gpsList.add(gps);
            } catch (Exception e) {
            }
        }
        String aa=JSONObject.toJSONString(gpsList);
        System.out.println(aa);
        //组装发送短信数据
//        note.setType(EnumNote.REGISET);
//        amqpTemplate.convertAndSend("school-system-note", JSONObject.toJSONString(note));
        return "kkkkk";
    }
}
